package action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Student;
import service.impl.StudentServiceImpl;

@WebServlet("/addStudentAction")
public class AddStudentAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private StudentServiceImpl studentService = new StudentServiceImpl();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddStudentAction() {
        super();
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		Student student = new Student();
		student.setName(request.getParameter("stuName"));
		student.setAge(Integer.valueOf(request.getParameter("stuAge")));
		
		String message = studentService.addStudent(student);
		
		response.getWriter().append(message);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
